package alg;


import java.sql.*;

import exception.*;
import org.apache.commons.configuration.*;

public class DatasourceMySql {

	public Connection getConnection() throws PersistenceException,
			ConfigurationException {

		Connection connection;
		ConfigManager config;
		String db_uri;
		String db_pass;
		String db_user;

		config = ConfigManager.getInstance();
		db_pass = config.get("db.password");
		db_user = config.get("db.username");
		db_uri = "jdbc:mysql://" 
				+ config.get("db.host") + ":"
				+ config.get("db.port") + "/" 
				+ config.get("db.schema") +
				"?allowMultiQuery=true";
		//System.out.println(db_uri);
		try {
			Class.forName("com.mysql.jdbc.Driver");
			connection = DriverManager.getConnection(db_uri, db_user, db_pass);
			return connection;
		} catch (Exception e) {
			throw new PersistenceException(e);
		}

	}
}
